# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=wget
pkgver=1.19.5
pkgrel=1
pkgdesc="A network utility to retrieve files from the Web"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/wget/"
license=('GPL3')
groups=('base-devel')
depends=('gcc-libs' 'libiconv' 'libidn2' 'libintl' 'libgpgme' 'libmetalink' 'libpcre' 'libpsl' 'libuuid' 'openssl' 'zlib')
makedepends=('gettext-devel' 'libidn2-devel' 'libgpgme-devel' 'libmetalink-devel' 'libuuid-devel' 'libpsl-devel' 'openssl-devel' 'pcre-devel' 'zlib-devel' 'python3' 'libunistring-devel')
checkdepends=('perl-HTTP-Daemon' 'perl-IO-Socket-SSL')
optdepends=('ca-certificates: HTTPS downloads')
backup=('etc/wgetrc')
install=wget.install
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.lz{,.sig}
        1.13.4-sysconfdir.patch
        wget-1.14-msys2.patch
        fix-gettext-version.patch)
sha256sums=('29fbe6f3d5408430c572a63fe32bd43d5860f32691173dfd84edc06869edca75'
            'SKIP'
            'c397093e82b50bcc6a4112a14b22d7426e67ce853d0dae65170aec6d7def4de8'
            '162f4e63fe759e2eb7a507179d02f840143ee914b7f9a32bbb65afbfd6aa3640'
            '47c50fc5157ab878da8d40e8e07d8aa778a2a6e8f625260bca646796f32501f7')
validpgpkeys=('7845120B07CBD8D6ECE5FF2B2A1743EDA91A35B6') # Tim Rühsen <tim.ruehsen@gmx.de>

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p2 -i "${srcdir}/1.13.4-sysconfdir.patch"
  patch -p1 -i "${srcdir}/wget-1.14-msys2.patch"
  patch -p1 -i "${srcdir}/fix-gettext-version.patch"

  autoreconf -fiv
  cat >> doc/sample.wgetrc <<EOF

# default root certs location
ca_certificate=/usr/ssl/certs/ca-bundle.crt
EOF
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --with-ssl=openssl \
    --with-libpsl \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --without-libpth-prefix \
    --without-libgnutls-prefix

  make
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  #make check
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
}
